package cn.bugio.note.controller.user;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author Vincent Vic
 * @version 1.0
 * @Description
 * @since 2021/2/24
 */

@RestController
@RequestMapping("/u/")
@RefreshScope //动态刷新
public class TestController {

    @Autowired
    private DiscoveryClient discoveryClient;

    /**
     * 测试：服务发现，证明找到内容中心信息
     * @return
     */
    @GetMapping("test")
    public List<ServiceInstance> getInstances(){
        System.out.println("1");
        return discoveryClient.getInstances("content-center");
    }

    @Value("${test.config}")
    private String config;

    /**
     * 测试：服务发现，证明找到内容中心信息
     * @return
     */
    @GetMapping("config")
    public String config(){
        return config;
    }
}
